//
//  EJSOffLinePayForOrderViewController.m
//  EnjoyShoppingStreet
//
//  Created by lifayu on 2018/1/10.
//  Copyright © 2018年 lifayu. All rights reserved.
//

#import "EJSOffLinePayForOrderViewController.h"
#import "EJSOrderListViewController.h"
#import "EJSGetOfflineInfoRequest.h"
#import "EJSOrderModel.h"
#import "EJSOfflinePayRequest.h"

@interface EJSOffLinePayForOrderViewController ()
@property (weak, nonatomic) IBOutlet UILabel *amountLabel;
@property (weak, nonatomic) IBOutlet UILabel *bankNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *bankNumLabel;
@property (weak, nonatomic) IBOutlet UILabel *promptLabel;


@end

@implementation EJSOffLinePayForOrderViewController


+ (instancetype)viewController
{
    UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    return [storyBoard instantiateViewControllerWithIdentifier:@"EJSOffLinePayForOrderViewController"];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"线下支付";
    [self configNavigationLeftItemWithImage:nil];
    [self getOfflinePayInfo];
    
    self.amountLabel.text = [NSString stringWithFormat:@"€ %.2f",self.orderModel.totalAmount.floatValue];
}

- (void)configNavigationLeftItemWithImage:(UIImage *)image
{
    UIImage *leftImage = [UIImage imageNamed:@"back_icon"];
    if(image)
    {
        leftImage = image;
    }
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn addTarget:self action:@selector(leftBarButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [btn setImage:leftImage forState:UIControlStateNormal];
    [btn setImage:leftImage forState:UIControlStateHighlighted];
    btn.size = btn.currentImage.size;
    
    UIBarButtonItem *leftBarItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
    self.navigationItem.leftBarButtonItem = leftBarItem;
    
}
- (void)leftBarButtonAction:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)getOfflinePayInfo{
    EJSGetOfflineInfoRequest *req = [EJSGetOfflineInfoRequest new];
    req.orderId = self.orderModel.orderId;
    [req asyncRequestWithsuccessHandler:^(BaseResponse *response) {
        EJSOfflinePayInfoModel *model = response.data;
        self.bankNameLabel.text = [NSString stringWithFormat:@"开户行：%@", model.bank];
        self.bankNumLabel.text = [NSString stringWithFormat:@"银行账号：%@", model.bankAccount];
        self.promptLabel.text = model.bankIntro;
    } failHandler:^(BaseResponse *response) {
        [[HUDHelper sharedInstance] tipMessage:response.message];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)payAction:(UIButton *)sender {
    EJSOfflinePayRequest *req = [EJSOfflinePayRequest new];
    req.orderId = self.orderModel.orderId;
    [req asyncRequestWithsuccessHandler:^(BaseResponse *response) {
        if(response.success){
            [HUDHelper alertTitle:@"提示" message:@"下单成功" cancel:@"确定" action:^{
                [self.navigationController popToRootViewControllerAnimated:YES];
            }];
        }else{
            [HUDHelper alertTitle:@"提示" message:response.message cancel:@"确定" action:^{
            }];
        }
        
    } failHandler:^(BaseResponse *response) {
        [HUDHelper alertTitle:@"提示" message:response.message cancel:@"确定" action:^{
        }];
    }];
   
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 4;
}

@end
